package com.yl.chainStore.task

import com.yl.chainStore.common.enums.Status
import com.yl.chainStore.pojo.vo.sick.CustomerSubscribeLogOperationVo
import com.yl.chainStore.pojo.vo.sick.CustomerSubscribeLogSelectVo
import com.yl.chainStore.services.ICustomerInfoService
import com.yl.chainStore.services.IWebSystemService
import com.yl.chainStore.services.sick.ICustomerSubscribeLogService
import org.slf4j.LoggerFactory
import org.springframework.scheduling.annotation.Scheduled
import org.springframework.stereotype.Component
import java.text.SimpleDateFormat
import java.util.*

/**
 * @description :简单定时
 * @author :吴枫
 * @create :2021-07-05 09:53:00
 */
@Component
open class ScheduledTasks(
	private val iWebSystemService: IWebSystemService,
	private val iCustomerSubscribeLogService: ICustomerSubscribeLogService,

	private val iCustomerInfoService: ICustomerInfoService
) {
	private val dateFormat = SimpleDateFormat("HH:mm:ss")
	private val log = LoggerFactory.getLogger(this::class.java)!!

	//    @Scheduled(fixedRate = 1000)
	open fun reportCurrentTime() {
		log.info("现在时间 , ${dateFormat.format(Date())}")
	}


	/**
	 * 预约转就诊记录（因为现在预约会直接生成就诊记录，所以暂时不用了）
	 */
//	@Scheduled(cron = "0 0 0 * * ?")
//    @Scheduled(cron = "0 4/5 * * * ?")
	open fun subscribeToHistory() {
		val logs = iWebSystemService.getAllSubscribeLog(
			CustomerSubscribeLogSelectVo(
				day = Date(),
				status = Status.NEW_ADD
			)
		)
		for (item in logs) {
			iCustomerSubscribeLogService.subLogToRecordsDetail(item)
			iCustomerSubscribeLogService.completeLog(CustomerSubscribeLogOperationVo(
				id = item.id
			))
		}
	}


}
